home *** CD-ROM | disk | FTP | other *** search
/ PC Advisor 2011 May / PC Advisor 190 E.iso / pc / ESSENTIALS / VLC Media Player 1.1 / vlc-1.1.5-win32.exe / lua / meta / art / 03_lastfm.lua < prev    next >
Encoding:
Text File  |  2010-11-13  |  1.7 KB  |  50 lines

  1. --[[
  2.  Gets an artwork from last.fm
  3.  
  4.  $Id$
  5.  Copyright ┬⌐ 2010 the VideoLAN team
  6.  
  7.  This program is free software; you can redistribute it and/or modify
  8.  it under the terms of the GNU General Public License as published by
  9.  the Free Software Foundation; either version 2 of the License, or
  10.  (at your option) any later version.
  11.  
  12.  This program is distributed in the hope that it will be useful,
  13.  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  GNU General Public License for more details.
  16.  
  17.  You should have received a copy of the GNU General Public License
  18.  along with this program; if not, write to the Free Software
  19.  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  20. --]]
  21.  
  22. -- Return the artwork
  23. function fetch_art()
  24.     if vlc.item == nil then return nil end
  25.     local meta = vlc.item:metas()
  26.     if meta["artist"] and meta["album"] then
  27.         title = meta["artist"].."/"..meta["album"]
  28.     else
  29.         return nil
  30.     end
  31.     -- remove -.* from string
  32.     title = string.gsub( title, " ?%-.*", "" )
  33.     -- remove (info..) from string
  34.     title = string.gsub( title, "%(.*%)", "" )
  35.     -- remove CD2 etc from string
  36.     title = string.gsub( title, "CD%d+", "" )
  37.     -- remove Disc \w+ from string
  38.     title = string.gsub( title, "Disc %w+", "" )
  39.     fd = vlc.stream( "http://www.last.fm/music/" .. title )
  40.     if not fd then return nil end
  41.     page = fd:read( 65653 )
  42.     fd = nil
  43.     _, _, arturl = string.find( page, "<img  width=\"174\" src=\"([^\"]+)\" class=\"art\" />\n" )
  44.     -- Don't use default album-art (not found one)
  45.     if not arturl or string.find( arturl, "default_album_mega.png") then
  46.        return nil
  47.     end
  48.     return arturl
  49. end
  50.